package com.www.applyword.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.www.applyword.R;
import com.www.applyword.bean.LocationBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huanghao on 2019/7/4.
 */

public class PoiAdapter extends BaseAdapter {
    private List<LocationBean> datas = new ArrayList<>();
    private Context activity;
    public  ImageView tv_prv_select;
    public  ImageView iv_check;

    public void upData(){
       // vh.iv_check.setVisibility(View.VISIBLE);
    }

    public PoiAdapter(Context context) {
        this.activity =  context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder vh = null;
        if(convertView == null){
            vh = new ViewHolder();
            convertView = LayoutInflater.from(activity).inflate(R.layout.item, parent, false);
            vh.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            vh.tv_text = (TextView) convertView.findViewById(R.id.tv_details);
            vh.iv_check = (ImageView) convertView.findViewById(R.id.iv_check);
            vh.ll = (LinearLayout) convertView.findViewById(R.id.ll);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        LocationBean bean = (LocationBean) getItem(position);
        vh.tv_title.setText(bean.getTitle());
        vh.tv_text.setText(bean.getContent());
        vh.iv_check.setVisibility(View.INVISIBLE);
        ViewHolder finalVh1 = vh;
       /* vh.ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_check = finalVh1.iv_check;
                if (tv_prv_select == iv_check){
                    iv_check.setVisibility(View.INVISIBLE);
                    tv_prv_select = null;
                    return;
                }

                iv_check.setVisibility(View.VISIBLE);
                if (tv_prv_select != null){
                    tv_prv_select.setVisibility(View.INVISIBLE);
                }
                tv_prv_select = iv_check;
            }
        });*/


        return convertView;
    }

    private class ViewHolder{
        public TextView tv_title;
        public TextView tv_text;
        public LinearLayout ll;
        public ImageView iv_check;
    }

    public void setData(List<LocationBean> datas){
        this.datas = datas;
        if(datas.size()>0){
            //iv_check.setVisibility(View.INVISIBLE);
        }else{
           // Toast.makeText(activity, "没有搜索结果", Toast.LENGTH_SHORT).show();
        }
    }
}

